from django.contrib.auth.models import AbstractUser
from django.db import models


class User(AbstractUser):
    avatar = models.ImageField(null=True, upload_to="static/avatars", default="static/avatars/default/default_avatar.jpg", verbose_name="用户头像", help_text="用户头像")
    signature = models.CharField(null=True, max_length=32, default="", verbose_name="用户签名", help_text="用户签名")
    introduction = models.TextField(null=True, default="", verbose_name="个人介绍", help_text="个人介绍")
    # auto_now_add: 只有第一次创建时自动更新
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")
    is_deleted = models.BooleanField(default=False, verbose_name="逻辑删除", help_text="逻辑删除")

    class Meta:
        db_table = "tb_user"
        verbose_name = "用户"
        verbose_name_plural = verbose_name

    def delete(self, using=None, keep_parents=False):
        """重写数据库删除方法实现逻辑删除"""
        self.is_deleted = True
        self.save()
